/*****************************************************************************
Copyright 2006 Kervin L. Pierre
    EMAIL: otlkcon@adevsoft.com

This file is part of Otlkcon.

Otlkcon is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

Otlkcon is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lesser GNU General Public License for more details.

You should have received a copy of the Lesser GNU General Public License
along with Otlkcon; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*******************************************************************************/

#include "StdAfx.h"
#include "O_IMSLogon.h"

O_IMSLogon::O_IMSLogon(void)
{
}

O_IMSLogon::~O_IMSLogon(void)
{
}

STDMETHODIMP O_IMSLogon::QueryInterface (REFIID riid, void **ppv)
{
    HRESULT result = S_OK;

    OTLKCON_LOG_PRINTF(OTLKCON_LOG_LEVEL_INFO, OTLKCON_LOG_TARGET_ALL, L"inside O_ITable->QueryInterface. \
 {%0.8X-%0.4X-%0.4X-%0.2X%0.2X-%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X}\n",
        riid.Data1, riid.Data2, riid.Data3, riid.Data4[0], riid.Data4[1],
        riid.Data4[2], riid.Data4[3], riid.Data4[4], riid.Data4[5],
        riid.Data4[6], riid.Data4[7]);

    *ppv = NULL;

    if( memcmp(&riid, &IID_IUnknown, sizeof(IID)) &&
        memcmp(&riid, &IID_IMAPITable, sizeof(IID)))
    { 
        result = ResultFromScode(E_NOINTERFACE);
        return result;
    }

    AddRef();
    *ppv = (LPVOID)this;

    return result;
}

ULONG STDMETHODCALLTYPE O_IMSLogon::AddRef (void)
{
    return ++cRef;
}

ULONG STDMETHODCALLTYPE O_IMSLogon::Release(void)
{
    OTLKCON_LOG_PRINTF(OTLKCON_LOG_LEVEL_INFO,  OTLKCON_LOG_TARGET_ALL, L"O_IMSLogon::Release %d\n",
             cRef);

    if ( cRef == 1 )
    {
        Destroy();
		delete this;
		return 0;
    }

    return --cRef;
}
void O_IMSLogon::Create()
{
    lpAllocateBuffer    = NULL;
    lpAllocateMore      = NULL;
    lpFreeBuffer        = NULL;

    cRef = 1;
	lpMsgStoreObj		= NULL;
	lpMAPISup			= NULL;
}

void O_IMSLogon::Destroy()
{
    if(NULL != lpMsgStoreObj)
    {
    	lpMsgStoreObj->Release();
		lpMsgStoreObj = NULL;
    } // if
}

STDMETHODIMP O_IMSLogon::GetLastError( HRESULT rResult,
							   ULONG ulFlags, LPMAPIERROR *lppMAPIError)
{
  HRESULT result = MAPI_E_NO_SUPPORT;

  return result;
}

STDMETHODIMP O_IMSLogon::OpenEntry(
  ULONG cbEntryID,
  LPENTRYID lpEntryID,
  LPCIID lpInterface,
  ULONG ulOpenFlags,
  ULONG *lpulObjType,
  LPUNKNOWN *lppUnk 
)
{
  HRESULT result;

  result = lpMsgStoreObj->OpenEntry(cbEntryID,lpEntryID,
                                    lpInterface,ulOpenFlags,lpulObjType, lppUnk );
  return result;
}

STDMETHODIMP O_IMSLogon::Logoff( ULONG *lpulFlags )
{
    HRESULT result = S_OK;

    OTLKCON_LOG_PRINTF(OTLKCON_LOG_LEVEL_INFO, OTLKCON_LOG_TARGET_ALL, 
      L"inside IMSLogon->Logoff.\n");

    return result;
}


STDMETHODIMP O_IMSLogon::CompareEntryIDs(
  ULONG cbEntryID1,
  LPENTRYID lpEntryID1,
  ULONG cbEntryID2,
  LPENTRYID lpEntryID2,
  ULONG ulFlags,
  ULONG *lpulResult  
)
{
  HRESULT result;

  result = lpMsgStoreObj->CompareEntryIDs(cbEntryID1, lpEntryID1, 
                                            cbEntryID2, lpEntryID2,
                                            ulFlags, lpulResult );
  return result;
}

STDMETHODIMP O_IMSLogon::Advise(
  ULONG cbEntryID,
  LPENTRYID lpEntryID,
  ULONG ulEventMask,
  LPMAPIADVISESINK lpAdviseSink,
  ULONG FAR * lpulConnection       
)
{
  HRESULT result = S_OK;

  return lpMsgStoreObj->Advise(
	  cbEntryID,
	  lpEntryID,
	  ulEventMask,
	  lpAdviseSink,
	  lpulConnection);
}

STDMETHODIMP O_IMSLogon::Unadvise(
  ULONG ulConnection  
)
{
  HRESULT result = S_OK;

  return lpMsgStoreObj->Unadvise(
	  ulConnection);
}

STDMETHODIMP O_IMSLogon::OpenStatusEntry(
  LPCIID lpInterface,
  ULONG ulFlags,
  ULONG *lpulObjType,
  LPVOID *lppEntry  
)
{
  HRESULT result = MAPI_E_NO_SUPPORT;

  return result;
}